﻿using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace XNAFight.Engine.Inputs
{
    // Donne des fonctions statiques pour interpreter les inputs utilisés dans les menus
    public class MenuInputInterpreter
    {       
        // Validation d'une entrée
        public static bool isMenuItemSelected()
        {
            return InputState.isNewKeyPressed(Keys.Space) ||
                   InputState.isNewKeyPressed(Keys.Enter) ||
                   InputState.isNewButtonPressed(Buttons.Start) ||
                   InputState.isNewButtonPressed(Buttons.A) ;
        }
        public static bool isMenuItemSelected(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Space) ||
                   InputState.isNewKeyPressed(Keys.Enter);
            else
                return
                    InputState.isNewButtonPressed(Buttons.Start, _controler.Index) ||
                    InputState.isNewButtonPressed(Buttons.A, _controler.Index);
        }

        // Annulation
        public static bool isMenuCanceled()
        {
            return InputState.isNewKeyPressed(Keys.Escape) ||
                   InputState.isNewButtonPressed(Buttons.Back) ||
                   InputState.isNewButtonPressed(Buttons.B);
        }
        public static bool isMenuCanceled(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Escape);
            else
                return
                    InputState.isNewButtonPressed(Buttons.Back, _controler.Index) ||
                    InputState.isNewButtonPressed(Buttons.B, _controler.Index);
        }
        
        // Selection vers le haut
        public static bool isMenuUp()
        {
            return
                InputState.isNewKeyPressed(Keys.Up) ||
                InputState.isNewButtonPressed(Buttons.DPadUp) ||
                InputState.isLeftStickUpped();
        }
        public static bool isMenuUp(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Up);
            else
                return
                    InputState.isNewButtonPressed(Buttons.DPadUp, _controler.Index) ||
                    InputState.isLeftStickUpped(_controler.Index);
        }

        // Selection vers le bas
        public static bool isMenuDown()
        {
            return 
                InputState.isNewKeyPressed(Keys.Down) ||
                InputState.isNewButtonPressed(Buttons.DPadDown) ||
                InputState.isLeftStickDowned();
        }
        public static bool isMenuDown(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Down);
            else
                return
                    InputState.isNewButtonPressed(Buttons.DPadDown, _controler.Index) ||
                    InputState.isLeftStickDowned(_controler.Index);
        }

        // Selection vers la gauche
        public static bool isMenuLeft()
        {
            return
                InputState.isNewKeyPressed(Keys.Left) ||
                InputState.isNewButtonPressed(Buttons.DPadLeft) ||
                InputState.isLeftStickOnLeft(); ;
        }
        public static bool isMenuLeft(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Left);
            else
                return
                    InputState.isNewButtonPressed(Buttons.DPadLeft, _controler.Index) ||
                    InputState.isLeftStickOnLeft(_controler.Index);
        }

        // Selection vers la droite
        public static bool isMenuRight()
        {
            return
                InputState.isNewKeyPressed(Keys.Right) ||
                InputState.isNewButtonPressed(Buttons.DPadRight) ||
                InputState.isLeftStickOnRight(); ;
        }
        public static bool isMenuRight(Controler _controler)
        {
            if (_controler.Type == InputType.Keyboard)
                return
                   InputState.isNewKeyPressed(Keys.Right);
            else
                return
                    InputState.isNewButtonPressed(Buttons.DPadRight, _controler.Index) ||
                    InputState.isLeftStickOnRight(_controler.Index);
        }
        
        // Ouverture du menu de debug
        public static bool isDebugPressed()
        {
            return 
                InputState.isNewKeyPressed(Keys.F1) ||
                InputState.isNewButtonPressed(Buttons.RightStick);
        }
    }
}
